import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'dart:ui' as ui show ParagraphBuilder, PlaceholderAlignment;

import 'package:flutter3demo/common_util.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

///Users/marco/.pub-cache/hosted/pub.flutter-io.cn/charts_common-0.9.0/lib/src/common/style/style.dart

/// Donut chart with labels example. This is a simple pie chart with a hole in
/// the middle.

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // bb.arcStrokeColor = charts.Color.black;

    return MaterialApp(
      home: MyHomePage(),
      title: "ada",
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  MyHomePageState createState() => MyHomePageState();
}

//套在最里层Builder上单个Builder更新
class MyHomePageState extends State<MyHomePage>
    with SingleTickerProviderStateMixin {

  RefreshController refreshController = RefreshController();
  @override
  void initState() {
    super.initState();
  }

  int currentIndex = 0;
  int currentIndex2 = 0;

  @override
  Widget build(BuildContext context1) {
    return Scaffold(
      appBar: AppBar(title: Text("学习pulltorefresh"),),
      body: Container(
        color: Colors.white,
        child: Column(
          children: [
            Expanded(
                child: SmartRefresher(
                  controller: refreshController,
                  enablePullUp: true,
                  enablePullDown: true,
                  onRefresh: (){
                    Future.delayed(Duration(seconds: 2),(){
                      refreshController.refreshCompleted();
                    });
                  },
                  onLoading: (){
                    Future.delayed(Duration(seconds: 2),(){
                      refreshController.loadComplete();
                    });
                  },
                  child: ListView.separated(
                      itemBuilder: (BuildContext context, int index) {
                        return Container(
                          margin: EdgeInsets.all(10),
                          width: 100,
                          height: 100,
                          color: CommonUtil.randomColor(),
                        );
                      },
                      separatorBuilder: (BuildContext context, int index) {
                        return Container(
                          height: 3,
                          color: CommonUtil.randomColor(),
                        );
                      },
                      itemCount: 3),
                ))
          ],
        ),
      ),
    );
  }
}
